home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / doc / clippings / 920131-01 < prev    next >
Encoding:
Internet Message Format  |  1992-03-20  |  7.0 KB

  1. From: wietse@wzv.win.tue.nl (Wietse Venema)
  2. Newsgroups: alt.security,alt.sources,comp.sys.sun.admin
  3. Subject: fixing the LD_LIBRARY_PATH problem (source)
  4. Keywords: SunOS, sync, breakins, passwords
  5. Message-ID: <2902@wzv.win.tue.nl>
  6. Date: 31 Jan 92 21:01:12 GMT
  7. References: <799@itexjct.jct.ac.il> <5317@stl.co.uk> <1992Jan28.133241.17998@cccan.uucp> <v70r=af@rpi.edu>
  8. Organization: Eindhoven University of Technology, The Netherlands
  9.  
  10. Recent articles in alt.security discuss the possibilities to introduce
  11. trojan horses via the SunOS 4.x LD_LIBRARY_PATH environment variable.
  12.  
  13. Examples involve the password-less "sync" account. By default, it has
  14. the same uid as the "daemon" account, which is the owner of the printer
  15. spooling subsystem. The "login -p" (preserve environment) and "su"
  16. (without switches) commands can both be used for this purpose.
  17.  
  18. Getting rid of password-less accounts (or giving them a unique user id
  19. that does not own any files) does help, but it does not eliminate the
  20. underlying problems. These problems are tied to the way LD_LIBRARY_PATH
  21. interacts with commands such as "login" and "su".
  22.  
  23. Some background: according to the SunOS 4.x ld.so manual page, the
  24. LD_LIBRARY_PATH variable is ignored with set-uid programs (effective
  25. uid != real uid).  This is a good idea with programs like "login" and
  26. "su", but it solves only part of the problem.  Reason:  both commands
  27. set the effective and real uids to the same value, thus making their
  28. offspring susceptible to LD_LIBRARY_PATH tricks.
  29.  
  30. My conclusion is that commands like "login" and "su" should not pass on
  31. any LD_LIBRARY_PATH information. The "login" command is easily fixed:
  32. the following step has already been suggested in other articles:
  33.  
  34.     - Disable world-execute permission on /usr/bin/login, so that the
  35.       "-p" option (preserve environment) can no longer be abused.
  36.  
  37. Revoking world-execute permission of the "su" command is not productive.
  38. The following steps are more practical:
  39.  
  40.     - Run a modified /usr/bin/su that clears LD_LIBRARY_PATH (see source
  41.       attached to the end of this article).
  42.  
  43.     - Delete /usr/5bin/su. With SunOS 4.1.1, it gives root a path with 
  44.       "." at the front, which is totally ridiculous anyway.
  45.  
  46. My SunOS 4.x "su" replacement is in the form of patches to source from
  47. the latest BSD source release, available from ftp.uu.net (directory
  48. /packages/bsd-sources) and many other places, such as ftp.win.tue.nl
  49. (directory /pub/bsd-sources).  The following files are required:
  50.  
  51.     .../bsd-sources/usr.bin/su/su.c.Z
  52.     .../bsd-sources/lib/libc/stdlib/getenv.c.Z
  53.     .../bsd-sources/lib/libc/stdlib/putenv.c.Z
  54.     .../bsd-sources/lib/libc/string/strdup.c.Z
  55.  
  56. The patch can be found in the attached shar file. The reader can easily
  57. verify that all it does is to change some messages to SunOS style, and
  58. to clean up the environment.
  59.  
  60.     Wietse
  61.  
  62. #! /bin/sh
  63. # This is a shell archive.  Remove anything before this line, then unpack
  64. # it by saving it into a file and typing "sh file".  To overwrite existing
  65. # files, type "sh file -c".  You can also feed this as standard input via
  66. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  67. # will see the following message at the end:
  68. #        "End of shell archive."
  69. # Contents:  diffs Makefile
  70. # Wrapped by wietse@wzv on Fri Jan 31 21:19:01 1992
  71. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  72. if test -f diffs -a "${1}" != "-c" ; then 
  73.   echo shar: Will not over-write existing file \"diffs\"
  74. else
  75. echo shar: Extracting \"diffs\" \(2871 characters\)
  76. sed "s/^X//" >diffs <<'END_OF_diffs'
  77. X*** su.c-    Fri Jan 31 13:42:53 1992
  78. X--- su.c    Fri Jan 31 21:06:51 1992
  79. X***************
  80. X*** 48,56 ****
  81. X--- 48,66 ----
  82. X  #include <stdio.h>
  83. X  #include <pwd.h>
  84. X  #include <grp.h>
  85. X+ #ifdef sun /* string stuff */
  86. X+ #include <strings.h>
  87. X+ char *strdup();
  88. X+ #else
  89. X  #include <string.h>
  90. X+ #endif
  91. X  #include <unistd.h>
  92. X+ #ifdef sun /* no <paths.h> file */
  93. X+ #define _PATH_BSHELL    "/bin/sh"
  94. X+ #define _PATH_DEFPATH    "/usr/bin:/usr/ucb"
  95. X+ #else
  96. X  #include <paths.h>
  97. X+ #endif
  98. X  
  99. X  #ifdef KERBEROS
  100. X  #include <kerberosIV/des.h>
  101. X***************
  102. X*** 114,120 ****
  103. X--- 124,132 ----
  104. X      prio = getpriority(PRIO_PROCESS, 0);
  105. X      if (errno)
  106. X          prio = 0;
  107. X+ #ifndef sun /* do not muck with process priority */
  108. X      (void)setpriority(PRIO_PROCESS, 0, -2);
  109. X+ #endif
  110. X      openlog("su", LOG_CONS, 0);
  111. X  
  112. X      /* get current login name and shell */
  113. X***************
  114. X*** 153,159 ****
  115. X--- 165,175 ----
  116. X              for (g = gr->gr_mem;; ++g) {
  117. X                  if (!*g) {
  118. X                      (void)fprintf(stderr,
  119. X+ #ifdef sun /* generate SunOS-like go-away message */
  120. X+                 "You do not have permission to su root.\n",
  121. X+ #else
  122. X                  "su: you are not in the correct group to su %s.\n",
  123. X+ #endif
  124. X                          user);
  125. X                      exit(1);
  126. X                  }
  127. X***************
  128. X*** 166,173 ****
  129. X--- 182,194 ----
  130. X              if (strcmp(pwd->pw_passwd, crypt(p, pwd->pw_passwd))) {
  131. X                  fprintf(stderr, "Sorry\n");
  132. X                  syslog(LOG_AUTH|LOG_WARNING,
  133. X+ #ifdef sun /* generate SunOS-like syslog messages */
  134. X+                     "'su %s' failed for %s%s", user,
  135. X+                     username, ontty());
  136. X+ #else
  137. X                      "BAD SU %s to %s%s", username,
  138. X                      user, ontty());
  139. X+ #endif
  140. X                  exit(1);
  141. X              }
  142. X          }
  143. X***************
  144. X*** 212,217 ****
  145. X--- 233,243 ----
  146. X          exit(1);
  147. X      }
  148. X  
  149. X+ #ifdef sun /* Security: clear LD_LIBRARY_PATH, unless invoked by root. */
  150. X+     if (ruid)
  151. X+         unsetenv("LD_LIBRARY_PATH");
  152. X+     unsetenv("IFS"); /* Sheesh, what did Sun do with /usr/bin/sh... */
  153. X+ #endif
  154. X      if (!asme) {
  155. X          if (asthem) {
  156. X              p = getenv("TERM");
  157. X***************
  158. X*** 240,250 ****
  159. X--- 266,283 ----
  160. X      /* csh strips the first character... */
  161. X      *np = asthem ? "-su" : iscsh == YES ? "_su" : "su";
  162. X  
  163. X+ #ifdef sun /* generate SunOS-like syslog messages */
  164. X+     syslog(LOG_NOTICE|LOG_AUTH, "'su %s' succeeded for %s%s",
  165. X+         user, username, ontty());
  166. X+ #else
  167. X      if (ruid != 0)
  168. X          syslog(LOG_NOTICE|LOG_AUTH, "%s to %s%s",
  169. X              username, user, ontty());
  170. X+ #endif
  171. X  
  172. X+ #ifndef sun /* do not muck with process priority */
  173. X      (void)setpriority(PRIO_PROCESS, 0, prio);
  174. X+ #endif
  175. X  
  176. X      execv(shell, np);
  177. X      (void)fprintf(stderr, "su: %s not found.\n", shell);
  178. X*** strdup.c-    Fri Jan 31 15:33:43 1992
  179. X--- strdup.c    Fri Jan 31 15:47:42 1992
  180. X***************
  181. X*** 35,40 ****
  182. X--- 35,43 ----
  183. X  static char sccsid[] = "@(#)strdup.c    5.4 (Berkeley) 2/24/91";
  184. X  #endif /* LIBC_SCCS and not lint */
  185. X  
  186. X+ #ifdef sun /* for u_int */
  187. X+ #include <sys/types.h>
  188. X+ #endif
  189. X  #include <stddef.h>
  190. X  #include <stdlib.h>
  191. X  #include <string.h>
  192. END_OF_diffs
  193. if test 2871 -ne `wc -c <diffs`; then
  194.     echo shar: \"diffs\" unpacked with wrong size!
  195. fi
  196. # end of overwriting check
  197. fi
  198. if test -f Makefile -a "${1}" != "-c" ; then 
  199.   echo shar: Will not over-write existing file \"Makefile\"
  200. else
  201. echo shar: Extracting \"Makefile\" \(104 characters\)
  202. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  203. XCFLAGS    = -O -Dconst=
  204. XOBJS    = su.o setenv.o getenv.o strdup.o
  205. X
  206. Xsu:    $(OBJS)
  207. X    $(CC) $(CFLAGS) -o $@ $(OBJS)
  208. END_OF_Makefile
  209. if test 104 -ne `wc -c <Makefile`; then
  210.     echo shar: \"Makefile\" unpacked with wrong size!
  211. fi
  212. # end of overwriting check
  213. fi
  214. echo shar: End of shell archive.
  215. exit 0
  216.  
  217.